/**
 * Created by Administrator on 2017/9/20.
 */
requirejs.config({
	baseUrl: '../js',
	paths: {
		jquery: 'lib/jquery',
		cookie: 'lib/jquery.cookie'
	}
})
requirejs(['jquery','cookie'], function ($) {
	$(function () {
		var cookie=$.cookie('login');
		if(cookie){
			var obj=JSON.parse(cookie);
			$('input[name="account"]').val(obj.name);
			$('input[name="userPassword"]').val(obj.pwd);
		}
		
		
		$('#btn').on('click',function () {
			$.ajax({
				url:"http://127.0.0.1/H5-1706/juhuimai/login.php",
				type:'post',
				data:$('#formUser').serialize(),
				success:function (res) {
					if(res){
					    alert(JSON.parse(res)['msg']);
					    if(JSON.parse(res)['status']==1){
							if($('.safty input[type="checkbox"]:checked')){
								var tempData={};
								tempData.name=$('input[name="account"]').val();
								tempData.pwd=$('input[name="userPassword"]').val();
								$.cookie('login',JSON.stringify(tempData),{expries:7})
							}
							else {
								var date = new Date()
								date.setDate(date.getDate() - 10000);
								$.cookie('login',{expries:date});
							}
							$(window).attr("location","index.html")
						}
					}
				}
			})
		})
	})
	
})